//
//  NGHomeCircleCell.swift
//  NingguoForum
//
//  Created by zhengsw on 2021/1/23.
//  Copyright © 2021 zhengsw. All rights reserved.
//

import UIKit
public protocol NGHomeCircleCellDelegate: NSObjectProtocol {
    func circleViewClick(model:HomeCircle);
}

class NGHomeCircleCell: UITableViewCell {
    var circleView:ZJCircleView! = nil
    var datas: Array<HomeCircle>? = nil
    weak open var delegate: NGHomeCircleCellDelegate?


    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        circleView = ZJCircleView(frame:CGRect(x: 0, y: 0, width: KSCREEN_WIDTH, height: 150))
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        circleView.delegate = self
        self.contentView.addSubview(circleView)
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setModel(datas:Array<HomeCircle>){
        self.datas = datas
        let items = NSMutableArray()
        let imgUrls = NSMutableArray()
        for  model in datas {
//            titles.add(model.title)
            let dict = model.pic_arr[0] as! NSDictionary
            imgUrls.add(dict.object(forKey: "url") as! String)
            items.add(ZJCircleViewItem(image: dict.object(forKey: "url") as! String, title: model.title))
            
        }
//        circleView.titles = titles as! [String]
//        circleView.setImageNames(images: imgUrls as! Array<Any>)
        
        circleView.configure(with: items as! [ZJCircleViewItem])
    }
    
}

extension NGHomeCircleCell: ZJCircleViewDelegate {
    func circleView(_ circleView: ZJCircleView, didClickAtIndex index: Int) {
        guard let model = self.datas?[index] else { return  }//数组会越界
        delegate?.circleViewClick(model: model)
    }
}
